﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quality_Calculator.Skills
{
    class TouchSkill : SkillBase
    {
        public double Efficiency { get; set; }
        public int Chance { get; set; }

        protected int UsageCount { get; set; }
        protected int SuccessCount { get; set; }
        protected double TotalEfficiency { get; set; }

        public double AvgEfficiency
        {
            get
            {
                return TotalEfficiency / (double)SuccessCount;
            }
        }
        public double FailRate
        {
            get
            {
                return ((double)(UsageCount - SuccessCount) / (double)UsageCount) * 100f;
            }
        }
        public override void SpellEffect(Synthesis synth)
        {
            UsageCount++;
            GenericTouch(Efficiency, Chance, synth);
        }
        protected void GenericTouch(double efficiency, int chance,Synthesis synth)
        {
            if (synth.HasBuff(eSpell.SteadyHands)) chance = chance + 20;
            if (synth.HasBuff(eSpell.SteadyHands2)) chance = chance + 30;
            if (synth.Randomize() <= chance)
            {
                double TouchEffect = 0;
                if (!synth.HasBuff(eSpell.Ingenuity))
                    TouchEffect = Formulas.QualityStar1(synth.CurrentControl);
                else
                    TouchEffect = Formulas.QualityStar1Inge(synth.CurrentControl);
                if (synth.State == eState.Good)
                    TouchEffect *= 1.5;
                if (synth.State == eState.Poor)
                    TouchEffect *= 0.5;
                if (synth.State == eState.Excellent)
                    TouchEffect *= 4;
                TouchEffect *= efficiency;
                if (synth.HasBuff(eSpell.GreatStrides))
                {
                    synth.Buffs.RemoveAll(p => p.Spell.Enum == eSpell.GreatStrides);
                    TouchEffect *= 2;
                }
                if (synth.HasBuff(eSpell.InnerQuiet))
                    synth.InnerQuietStacks++;                
                synth.QualityCurrent += (int)Math.Round(TouchEffect);

                //stats
                SuccessCount++;
                TotalEfficiency += TouchEffect;
            }
            synth.LooseDurability(10);
        }
    }
}
